package com.yuyou.train.user.controller;

import io.swagger.annotations.ApiOperation;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;  import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yuyou.train.service.api.user.entity.UserRemind;
import com.yuyou.train.user.service.IUserRemindService;
import com.yuyou.train.util.bean.LoginRedisObj;
import com.yuyou.train.util.bean.PageParams;
import com.yuyou.train.util.bean.Pagination;
import com.yuyou.train.util.bean.ReturnResult;


@Validated
@RestController
@RequestMapping(value="/api/userRemind")
public class UserRemindController extends BaseController{

	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private IUserRemindService userRemindService;

	@ApiOperation(value = "我的提醒(前台)")
	@RequestMapping(value="/findMyRemindPage",method= RequestMethod.POST)
	public ReturnResult<Pagination<UserRemind>> findMyRemindPage(@Validated @ModelAttribute PageParams pageParams,
														 	 	 HttpServletRequest request){

		LoginRedisObj loginObj = this.getUserObj(request);
		Map<String, Object> conditions=new HashMap<>();
		Pagination<UserRemind> queryPgn = new Pagination<>();
		conditions.put("receUserId", loginObj.getUserId());
		queryPgn.setConditions(conditions);
		queryPgn.setPageParams(pageParams);

		int total = userRemindService.findUserRemindPageCount(queryPgn);
		queryPgn.setTotal(total);
		queryPgn.toBePage();
		if(total > 0){
			queryPgn.setTotal(total);
			List<UserRemind> list = userRemindService.findUserRemindPage(queryPgn);
			queryPgn.setList(list);
		}
		return ReturnResult.success(queryPgn);
	}

}
